#ifndef BINARYCONSTRAINT_H
#define BINARYCONSTRAINT_H

#include "variable.h"

namespace fcsp {
class BinaryConstraint {
public:
  // constructors
  BinaryConstraint(Variable *x, Variable *y);
  BinaryConstraint(Variable *x, Variable *y, std::map< int, std::map<int, double> > preferences);

  // destructors
  virtual ~BinaryConstraint() { }
  void Destroy() const;
  
  // accessors
  Variable &x() const { return *x_; }
  Variable &y() const { return *y_; }
  const std::map< int, std::map<int, double> > &preferences() const { return preferences_; }

  // operators
  // two constraint are equal if the variables involved in it are the same and in the same order
  inline bool operator==(const BinaryConstraint &bc) const {
    return x().id() == bc.x().id() && y().id() == bc.y().id();
  }
  
  // methods
  void AddPreference(int value_x, int value_y, double pref); // add a new preference
  bool SetPreference(int value_x, int value_y, double pref); // set a preference value
  double GetPreference(int value_x, int value_y) const; // get a preference value
  // get all the preferences of value_x of x variable in tne constraint
  std::pair<std::map<int, double> &, bool> GetPreferences(int value_x);
  bool RemovePreference(int value_x, int value_y); // remove a preference
  bool IsValue(int value_x, int value_y); // check if value_x and value_x are valid for x and y
  
private:
  // data
  Variable *x_; // first variable of constraint
  Variable *y_; // second variable of constraint
  std::map< int, std::map<int, double> > preferences_; // preferences of constraint
}; // class BinaryConstraint
} // namespace fcsp
#endif	// BINARYCONSTRAINT_H

